package com.zt.bigdata.flink.stream

import org.apache.flink.streaming.api.scala.{DataStream, StreamExecutionEnvironment, _}

/**
  * @ClassName ApplyDemo
  * @Description
  * @Author zhangtonghy
  * @Date 2019-07-16 11:10
  * @Copyright: 版权所有 (C) zt zt.
  * @注意 ：本内容仅限于zt内部传阅，禁止外泄以及用于其他的商业目的
  **/
object SplitDemo {


  def main(args: Array[String]): Unit = {
    val env = StreamExecutionEnvironment.getExecutionEnvironment
    env.setParallelism(4)
    val word: DataStream[String] = env.socketTextStream("localhost", 999)


    val split = word
      .flatMap(_.split("\\s+"))
      .filter(_.nonEmpty)
      .map(_.toInt)
      .keyBy(_ % 4)
      .split((num: Int) =>
        (num % 2) match {
          case 0 => List("even")
          case 1 => List("odd")
        })



    val even = split.select("even")
    even.print()

    env.execute()
  }
}
